package com.WicsApp.android;

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.TextView;

public class EventsActivity extends BaseActivity {
    /** Called when the activity is first created. */
    @Override
    public void setContentView(View view) {
     super.setContentView(view);
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.events);
        
        Document doc;
		try {
			//doc = Jsoup.connect("http://cgi.sfu.ca/~wics/category/events").timeout(1000000).get();
			doc = Jsoup.connect("http://cgi.sfu.ca/~wics/?cat=4").timeout(1000000).get();
			String name = new String();
			//select the text of the events
			Elements elss = doc.getElementsByClass("entry");
			//select only the first event and get each paragraph
			Elements els = elss.first().select("p");
			
			for(org.jsoup.nodes.Element el : els){
				//append a new line after each paragraph
				name +=el.text() + "\n";
			}
			
			TextView t = (TextView) findViewById(R.id.TextView3);
			t.setMovementMethod(new ScrollingMovementMethod());
			t.setText(name);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
    }
}